<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="title='编辑菜单'">
<meta charset="utf-8">
<header th:replace="header::headerFragment(${title})"></header>
<body class="gray-bg">
	<div class="wrapper wrapper-content ">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="MenuForm">
							<input id="menuId" name="menuId" th:value="${menu.menuId}" type="hidden" /> <input id="parentId" name="parentId" th:value="${menu.parentId}" type="hidden" />
							<div class="form-group">
								<label class="col-sm-3 control-label">菜单名称：</label>
								<div class="col-sm-8">
									<input id="name" name="name" th:value="${menu.name}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">菜单类型：</label>
								<div class="col-sm-8">
									<label class="radio-inline"> <input type="radio" th:field="*{menu.type}" name="type" value="0" /> 目录
									</label> <label class="radio-inline"> <input type="radio" th:field="*{menu.type}" name="type" value="1" /> 菜单
									</label> <label class="radio-inline"> <input type="radio" th:field="*{menu.type}" name="type" value="2" /> 按钮
									</label>
								</div>
							</div>
							<div class="form-group ">
								<label class="col-sm-3  control-label">菜单URL：</label>
								<div class="col-sm-8">
									<input id="url" name="url" th:value="${menu.url}" class="form-control" placeholder="url地址注意填写相对路径" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">授权：</label>
								<div class="col-sm-8">
									<input id="perms" name="perms" th:value="${menu.perms}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">菜单图标：</label>
								<div class="col-sm-8">
									<input id="icon" name="icon" th:value="${menu.icon}" placeholder="选择图标" class="form-control" type="text"> 
									<span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 给这些图标加上 <code>fa-spin</code>，就可以表现出加载动画了</span>
									<div class="ms-parent" style="width: 100%;">
										<div class="icon-drop animated flipInX" style="display: none; max-height: 400px; overflow-y: auto">
											<div data-th-include="sys/menu/icon"></div>
										</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">排序号：</label>
								<div class="col-sm-8">
									<input id="orderNo" name="orderNo" th:value="${menu.orderNo}" class="form-control" type="text">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">状态：</label>
								<div class="col-sm-8">
									<label class="radio-inline"> <input th:field="*{menu.status}" type="radio" name="status" value="1" /> 正常
									</label> <label class="radio-inline"> <input th:field="*{menu.status}" type="radio" name="status" value="0" /> 禁用
									</label>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button type="submit" class="btn btn-primary">提交</button>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<div th:replace="footer :: footer"></div>
	<script type="text/javascript">
		var prefix = ctx + "/sys/menu/"
        $().ready(function() {
	        menuVisible();
	        validateRule();
	        $('input[type=radio][name=type]').change(function() {
		        menuVisible();
	        });

	        $("input[name='icon']").focus(function() {
		        $(".icon-drop").show();
	        });
	        $("#MenuForm").click(function(event) {
		        var obj = event.srcElement || event.target;
		        if (!$(obj).is("input[name='icon']")) {//非图标选择时隐藏图标域
			        $(".icon-drop").hide();
		        }
	        });
	        $(".icon-drop").find(".ico-list i").on("click",//增加图标选择事件
	        function() {
		        $('#icon').val($(this).attr('class'));
	        });
        });

        function menuVisible() {
	        menuType = $("input[name='type'][type=radio]:checked").val();
	        if (menuType == "0") {
		        $("#url").parents(".form-group").hide();
		        $("#perms").parents(".form-group").hide();
		        $("#icon").parents(".form-group").show();
	        } else if (menuType == "1") {
		        $("#url").parents(".form-group").show();
		        $("#perms").parents(".form-group").show();
		        $("#icon").parents(".form-group").show();
	        } else if (menuType == "2") {
		        $("#url").parents(".form-group").hide();
		        $("#perms").parents(".form-group").show();
		        $("#icon").parents(".form-group").hide();
	        }
        }

        function validateRule() {
	        var icon = "<i class='fa fa-times-circle'></i> ";
	        $("#MenuForm").validate({
	            rules : {
	                name : {
		                required : true
	                },
	                type : {
		                required : true
	                },
	                url : {
		                required : true
	                },
	                perms : {
		                required : true
	                },
	            },
	            messages : {
	                name : {
		                required : icon + "请输入菜单名称"
	                },
	                url : {
		                required : icon + "请输入菜单URL"
	                },
	                type : {
		                required : icon + "请选择菜单类型"
	                },
	                url : {
		                required : icon + "请输入菜单URL"
	                },
	                perms : {
		                required : icon + "请输入菜单对应权限信息"
	                },
	            }
	        })
        }

        $.validator.setDefaults({
	        submitHandler : function() {
		        update();
	        }
        });

        function update() {
	        yimo.ajaxPut({
	            url : prefix + "/update",
	            data : $('#MenuForm').serialize(),// 你的formid
	            needClose : true,
	            parentRefresh : true,
	        });
        }
	</script>
</body>
</html>
